home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 121_01 / tl370.c < prev    next >
Text File  |  1985-08-19  |  22KB  |  876 lines

  1. /*
  2. HEADER: CUG 121.??;
  3.  
  4.     TITLE:    tl370 - dumb terminal with file xfer;
  5.     VERSION:    1.0;
  6.     DATE:    01/05/86;
  7.     DESCRIPTION: "TL370 emulates a dumb terminal.  Incoming data may be
  8.         buffered in memory and written to disk, data may be
  9.         transmitted from disk to the modem, or files may be
  10.         formally transferred in a `checksum' mode with automatic
  11.         handshaking and buffering.
  12.         TL370 is a modified version of Telnet v2.3, as distributed
  13.         with v1.46 of the BDS C compiler.  The modification consists
  14.         of the addition of optional XON/XOFF handshaking for file
  15.         transmission.";
  16.     KEYWORDS:    terminal, modem, emulate, file transfer;
  17.     SYSTEM:    CP/M;
  18.     FILENAME:    TL370.C;
  19.     WARNINGS:    "Requires local.c for link.
  20.         The checksum file transfer does not follow the XMODEM
  21.         protocol.
  22.         TL370 assumes that the CP/M console is much faster than the
  23.         modem (e.g. a 1200+ baud console with a 300 baud modem).";
  24.     SEE-ALSO:    CALL.C, TEL.C, TELNET.C;
  25.     AUTHORS:    Leor Zolman, Leo Kenen, Ken Lonquest;
  26.     COMPILERS:    BDS-C 1.50;
  27. */
  28.  
  29. #define TITLE "BDS Telnet version 2.3        (July 1980)"
  30.  
  31. /*
  32.  
  33.     Written by Leor Zolman and Leo Kenen
  34.     December 1979, March 1980, May 1980, July 1980
  35.  
  36.     This version has been modified to obtain all hardware-
  37.     dependent information from bdscio.h, which must    contain
  38.     the correct hardware specifications for your modem port.
  39.     It is also no longer necessary to alter #define statements
  40.     in this file to reflect CP/M system size; the "topofmem()"
  41.     function is now used to determine the amount of memory 
  42.     available for the text collection buffer.
  43.  
  44.     If you intend to use this program for high speed
  45.     (i.e, greater than 300 baud) data transfers, such as
  46.     maybe over RS232 lines between two machines directly,
  47.     then the speed of transfer will be limited by the
  48.     processors involved instead of the baud rate;
  49.     UNDER SUCH CIRCUMSTANCES, A TRANSFER WILL ONLY WORK IF
  50.     THESE TWO CONDITIONS ARE MET:
  51.  
  52.         1) The transfer must always performd in BINARY
  53.            mode, never in TEXT mode, and
  54.         2) The receiving processor must be as fast or
  55.            FASTER than the transmitting processor. That
  56.            is, a 2 MHz machine may transmit to a 4 MHz
  57.            machine at, say, 9600 baud, BUT NOT VICE-
  58.            VERSA.
  59.  
  60.     See the write up by Leo for more details than are
  61.     presented here.
  62.  
  63.     ******************************************
  64.     * Telnet assumes that your CP/M console  *
  65.     * I/O device is much faster than your     *
  66.     * modem. On a 2MHz 8080, the modem can     *
  67.     * be receiving at up to 300 baud as long *
  68.     * as your console whips along (at the     *
  69.     * very least) at about 1200. 4 MHz mach- *
  70.     * ines might be able to get away with     *
  71.     * slower terminals, but not much slower. *
  72.     ******************************************
  73.  
  74. "Telnet" is a program which interacts with a modem to turn
  75.  your microcomputer into a very versatile terminal. Special
  76.  commands are entered to the program by typing the character
  77.  you designate as "SPECIAL", i.e, some character (such as the
  78.  null or ^A ) which you wouldn't be likely to need transmitted,
  79.  and then entering the appropriate command letter. Incoming
  80.  data may be buffered up in RAM memory and dumped to disk
  81.  whenever you desire (via the "o", "d", "c" and "k" commands),
  82.  data may be transmitted from disk to modem (via "t" and "a"),
  83.  or files can be formally transferred in an alternate
  84.  "checksum" mode which handles handshaking and buffering
  85.  automatically when interacting with the same program on
  86.  the other end of the line. During file transfers, you
  87.  may temporarily pause and later resume the transmission
  88.  (via the "p" and "r" commands.) There are also various
  89.  options you can control (see "n", "7", "h" and "l") to
  90.  adapt operation toward the type of file you wish to
  91.  transfer. The "q" command closes the output file (if open)
  92.  and quits to CP/M. The "s" command displays the status of
  93.  the program. "z" clears the console screen. Any other
  94.  command letter (such as, for example, "?") causes a list
  95.  of legal commands to be displayed.
  96.  
  97. In order to transmit or receive files in the checksum
  98. mode, both parties must make sure that their modems are
  99. operating in FULL-DUPLEX. When you are in full duplex,
  100. then what you type will NOT come right back at you from the
  101. modem; the only input you see from the modem is the data
  102. transmitted by the machine on the OTHER end of the line.
  103.  
  104. This program considers "half duplex" to be any situation
  105. in which the data you transmit comes right back at you;
  106. whether it is your modem that is performing the ehoing
  107. or a computer system far away doesn't really matter. In any
  108. case, checksumming and handshaking is not allowed under half-
  109. duplex operation, since erroneous characters would be received.
  110. When you run telnet, it will ask you whether
  111. or not you are in half-duplex, and perform accordingly. If
  112. you switch from half to full or vice-versa while running the
  113. program, use the "h" option to inform telnet of the fact.
  114.  
  115. To perform checksummed file transfer, a connection must
  116. first be established between the two parties. If both
  117. parties are operating in full duplex, one originating and the
  118. other answering, then telnet will both display what each
  119. types to the console and send it to the modem. If a file
  120. then needs to be transferred, then one user would give the
  121. "t" command (to transmit) and the other would give the "o"
  122. command (to open an output file.) If both users indicate
  123. checksum mode (rather than only one specifing checksum mode
  124. which will abort almost immediatly), then telnet will take
  125. it from there and perform the transfer. If the sender
  126. (transmitter) wants to suspend the transfer temporarily and
  127. continue later, he can use the "p" command. When the receiver
  128. sees that transmission has been suspended (when no data has
  129. been sent for a long time), then HE gives the "p" command also,
  130. and both users may type to each other. When ready to resume,
  131. the "r" command must be given by the RECEIVER first, and
  132. then the sender, to prevent data from being lost.
  133.  
  134. */
  135.  
  136. #include <bdscio.h>    /* System, h'ware constants    */
  137. #include <hardware.h>
  138.  
  139. #define SPECIAL 0x18    /*  The character you type to
  140.                signal a Telnet command
  141.                (should be obscure...I use
  142.                 a "control-x")    */
  143.  
  144.  
  145. /*
  146.     The following #defines need not be changed:
  147. */
  148.  
  149. #define    ACK    0x06    /* Ascii ACK for handshaking    */
  150. #define    NAK    0x15
  151. #define    EOT    0x04    /* End of transmission        */
  152. #define    ETX    0x03    /* Abort Transmission        */
  153. #define XON    0x11    /* Enable transmission        */
  154. #define XOFF    0x13    /* Disable transmission        */
  155.  
  156. /*
  157.     External variable declarations:
  158. */
  159.  
  160. char rflag;        /* receiving file open flag    */
  161. char tflag;        /* transmitting file open flag    */
  162. char shflag;    /* ascii(ctrl-S, ctrl-Q) handshaking enabled. */
  163. char chflag;        /* checksumming enabled flag    */
  164. char cflag;        /* text-collection enabled flag */
  165. char pflag;        /* pausing flag         */
  166. char spflag;        /* stripping parity bit flag    */
  167. char lflag;        /* list device enabled flag    */
  168. char nflag;        /* recognizing nulls flag    */
  169. char fflag;        /* true if changing CR-LF's into
  170.                 just CR when transmitting    */
  171. char lastc;        /* last char xmitted        */
  172. char dodflag;        /* true if displaying outging
  173.                data                */
  174. char didflag;        /* true if displaying incoming
  175.                data                */
  176. char hdflag;        /* true if effectively working
  177.                in half-duplex        */
  178. char abortf;        /* true when file I/O aborted    */
  179. char rbuf[BUFSIZ];     /* file I/O buffer for incoming
  180.                data file            */
  181. char tbuf[SECSIZ];     /* sector buffer for file being
  182.                transmitted            */
  183. char rname[20];     /* name of receiving file    */
  184. char tname[20];     /* name of transmitting file    */
  185. int rfd, tfd;        /* file descriptors        */
  186.  
  187. char *cptr;        /* pointer to free space in buf */
  188. unsigned free;        /* number of bytes free in buf    */
  189. int bcount;        /* counts bytes in current block
  190.                when checksumming        */
  191. int scount;        /* Number of sectors
  192.                  sent/received        */
  193. int checksum;        /* the checksum value itself    */
  194. char timoutf;        /* true if time-out happens
  195.                while waiting for modem data    */
  196. char *i;        /* odd-job char pointer     */
  197.  
  198. int dod_sav, did_sav;    /* scratch variables        */
  199.